cmake_minimum_required(VERSION 3.8)
project(simple_action_demo)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(std_msgs REQUIRED)

# 生成接口
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
  "action/Countdown.action"
  DEPENDENCIES std_msgs
)
# 包含生成的接口目录
include_directories(include)
include_directories(${CMAKE_CURRENT_BINARY_DIR})

# 创建Action服务端可执行文件
add_executable(countdown_action_server src/countdown_action_server.cpp)
ament_target_dependencies(countdown_action_server
  rclcpp
  rclcpp_action
  std_msgs
)
target_include_directories(countdown_action_server PRIVATE
  ${CMAKE_CURRENT_BINARY_DIR}
)

# 创建Action客户端可执行文件
add_executable(countdown_action_client src/countdown_action_client.cpp)
ament_target_dependencies(countdown_action_client
  rclcpp
  rclcpp_action
  std_msgs
)
target_include_directories(countdown_action_client PRIVATE
  ${CMAKE_CURRENT_BINARY_DIR}
)

# 链接生成的 action 接口（使用新方法）
rosidl_get_typesupport_target(cpp_typesupport_target
  ${PROJECT_NAME} "rosidl_typesupport_cpp")

target_link_libraries(countdown_action_server "${cpp_typesupport_target}")
target_link_libraries(countdown_action_client "${cpp_typesupport_target}")
# 安装
install(TARGETS
  countdown_action_server
  countdown_action_client
  DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY action
  DESTINATION share/${PROJECT_NAME}
)
if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
